<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>

                    <p:panel header="Department Stock Report by Batch" >

                        <h:panelGrid columns="6" >                           
                            <p:autoComplete id="dep" completeMethod="#{departmentController.completeDept}" 
                                            var="dept" itemLabel="#{dept.name}" itemValue="#{dept}" forceSelection="true" value="#{reportsStockVariant.department}" converter="departmentConverter"/>

                            <p:autoComplete id="cat" completeMethod="#{pharmaceuticalItemCategoryController.completeCategory}" 
                                            var="dept" itemLabel="#{dept.name}" itemValue="#{dept}" forceSelection="true" value="#{reportsStockVariant.category}" >
                            </p:autoComplete>
                            <p:commandButton ajax="false" value="Process" actionListener="#{reportsStockVariant.fillCategoryStocks()}" ></p:commandButton>
                            <p:commandButton value="Print" ajax="false" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                                <pe:exporter type="xlsx" target="tbl" fileName="Category_report"  />
                            </p:commandButton>  
                            <p:commandButton ajax="false" value="Save Records" action="#{reportsStockVariant.saveRecord()}"/>
                            <p:watermark for="dep" value="Department"/>
                            <p:watermark for="cat" value="Category"/>
                        </h:panelGrid>

                        <h:panelGroup id="gpBillPreview" styleClass="noBorder summeryBorder">
                            <p:dataTable id="tbl" value="#{reportsStockVariant.records}" var="i"  >
                                <f:facet name="header">
                                    <h:panelGrid columns="2">
                                        <h:outputLabel value="Department : #{reportsStockVariant.department.name} "/>   <br/>                                 
                                        <h:outputLabel value="Category : #{reportsStockVariant.category.name}"/>   
                                        <h:outputLabel value="Recorded By : #{reportsStockVariant.recordedBill.creater.name}"/>
                                        <h:outputLabel value="Recorded Time : #{reportsStockVariant.recordedBill.createdAt}"/>
                                    </h:panelGrid>
                                    <h:outputLabel value="Report Id : #{reportsStockVariant.recordedBill.id}"/>                                   
                                </f:facet> 

                                <p:column headerText="Item">
                                    <f:facet name="header">
                                        <h:outputLabel value="Item"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.item.name}" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="System Stock" style="text-align: right;" >
                                    <f:facet name="header">
                                        <h:outputLabel value="System Stock"/>    
                                    </f:facet>
                                    <h:outputLabel id="sysStock" value="#{i.systemStock}"  >
                                        <f:convertNumber integerOnly="true" ></f:convertNumber>
                                    </h:outputLabel>                                  
                                </p:column>
                              
                                <p:column headerText="Physical Stock" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Physical Stock"/>    
                                    </f:facet>
                                    <p:inputText autocomplete="off"   value="#{i.physicalStock}"  >
                                        <f:convertNumber integerOnly="true" ></f:convertNumber>
                                    </p:inputText>                             
                                </p:column>

                                <p:column headerText="System - Physical" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="System - Physical"/>    
                                    </f:facet>
                                    <h:outputLabel id="varSysPhy" value="#{i.systemStock-i.physicalStock}"  >
                                        <f:convertNumber integerOnly="true" ></f:convertNumber>
                                    </h:outputLabel>                    
                                </p:column>

                           
                                <p:columnGroup type="footer">
                                    <p:row>
                                        <p:column footerText="Total Value"/>
                                        <p:column footerText="#{reportsStockVariant.systemStockValue}">
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{reportsStockVariant.systemStockValue}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                     
                                        <p:column footerText="#{reportsStockVariant.physicalStockValue}">
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{reportsStockVariant.calCulatedStockValue}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column footerText="#{reportsStockVariant.systemStockValue-reportsStockVariant.physicalStockValue}">
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{reportsStockVariant.systemStockValue-reportsStockVariant.physicalStockValue}">
                                                    <f:convertNumber pattern="#,##0.00"/>
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                    
                                    </p:row>
                                </p:columnGroup>

                            </p:dataTable>


                        </h:panelGroup>
                    </p:panel>
                </h:form>


            </ui:define>


        </ui:composition>

    </h:body>
</html>
